package thread.waitandnotify;

import java.util.concurrent.TimeUnit;

/**
 * @author liweimin
 * @date 2021/4/30 15:19
 * @since
 */
public class Test3 {
    public static final Object lock = new Object();

    public static void main(String[] args) {
        Thread thread = new Thread(() -> {
            synchronized (lock) {
                try {
                    System.out.println("===========begin===========");

                    lock.wait();
                    System.out.println("===========end===========");

                } catch (InterruptedException e) {
                    System.err.println("===========wait等待被中断===========");
                }
            }
        });
        thread.start();

        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        thread.interrupt();
    }
}
